//
//  ItemTableViewCell.m
//  MKUI
//
//  Created by sushangjin on 2020/6/5.
//Copyright © 2020 sushangjin. All rights reserved.
//

#import "ItemTVCell.h"

@interface ItemTVCell ()

@end

@implementation ItemTVCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
	if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.nameLabel = [[UILabel alloc] init];
        self.nameLabel.numberOfLines = 0;
        self.nameLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:self.nameLabel];
        //
        self.button = [[MKUIFlowLayoutButton alloc] initWithContentStyle:MKUIFlowLayoutButtonContentStyleHorizontal];
        [self.button setImage:[UIImage mk_imageWithUIColor:[UIColor redColor]] forState:UIControlStateNormal];
        self.button.imageSize = CGSizeMake(20, 20);
        self.button.contentInsets = UIEdgeInsetsMake(5, 5, 5, 5);
        self.button.interitemSpacing = 5;
        [self.button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button mk_setBackgroundColorForNormalAndHighlightedState:[UIColor lightGrayColor]];
        [self.button setTitle:@"Go" forState:UIControlStateNormal];
        [self.button mk_addClickActionBlock:^(ItemTVCell *self) {
            [self.cellModel didClickSelf];
        } context:self];
        [self.contentView addSubview:self.button];
        //
        self.flowlayout = [[MKUIFlowLayoutConstraint alloc] initWithItems:@[self.nameLabel,self.button] constraintParam:(MKUIFlowLayoutConstraintParam_V_C_R) contentInsets:UIEdgeInsetsMake(10, 10, 10, 10) interitemSpacing:10];
        self.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
	}
	return self;
}
- (void)customLayoutSubviews{
	[super customLayoutSubviews];
	CGRect bounds = self.contentView.bounds;
    self.flowlayout.bounds = bounds;
    [self.flowlayout layoutItemsWithResizeItems:YES];
}
- (void)customReloadCellModel{
	[super customReloadCellModel];
    Item *modelObject = self.cellModel.modelValue;
    self.nameLabel.text = modelObject.name;
}

- (CGSize)customSizeThatFits:(CGSize)size{//动态高度
    return [self.flowlayout sizeThatFits:size resizeItems:YES];
}
@end
